#pragma once
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <locale.h>
#include <windows.h>
#include <conio.h>
#define KEY_PRESS(VK) ((GetAsyncKeyState(VK) & 0b1) ? 1 : 0)
#define INDEX_HIDDEN 9
#define INDEX_MARK 10
#define INDEX_BOMB 11
#define INDEX_VOID 12
#define INDEX_WRONG 13

typedef bool** VECTOR_2B;
typedef uint8_t** VECTOR_2U;

typedef enum
{
    OP_SWEEP = 0,
    OP_MARK = 1,
    QUICK_SWEEP = 2,
} Operation;

void clearScreen();
void initSystem();
void initMap(VECTOR_2B *mine, VECTOR_2U *map, int *size, int *count);

void spawnMine(VECTOR_2B mine, int x0, int y0, int size, int count);
void paintBoarder(int size);
void flushUI(VECTOR_2B mine, VECTOR_2U map, int size, int correct, int count);
int gameLoop(VECTOR_2B mine, VECTOR_2U map, int size, int count);
bool calculate(VECTOR_2B mine, VECTOR_2U map, int size, int count, int *correct, int *mark);

Operation handleMouseClick(int size, int *x, int *y);
bool opSweep(VECTOR_2B mine, VECTOR_2U map, int size, int x, int y);
bool opMark(VECTOR_2B mine, VECTOR_2U map, int size, int x, int y);
bool opQuickSweep(VECTOR_2B mine, VECTOR_2U map, int size, int x, int y);
void over(VECTOR_2B mine, VECTOR_2U map, int size);

bool postHandle(VECTOR_2B mine, VECTOR_2U map, int size, int count, int correct);
void fail(int correct, int total);
void victory(int correct, int total);
void clear(VECTOR_2B mine, VECTOR_2U map, int size);

bool (*operation[3])(VECTOR_2B mine, VECTOR_2U map, int size, int x, int y) = {opSweep, opMark, opQuickSweep};
void (*grade[2])(int correct, int total) = {fail, victory};

int modifier[8][2] = 
{
    {-1,-1},
    {-1, 0},
    {-1, 1},
    { 0,-1},
    { 0, 1},
    { 1,-1},
    { 1, 0},
    { 1, 1}
};

char mapStrs[14][5] =
{
    "  ",
    " 1",
    " 2",
    " 3",
    " 4",
    " 5",
    " 6",
    " 7",
    " 8",
    "🟦",
    "🚩",
    "💣",
    "🟦",
    "❌",
};